package com.discalis.android.maps;

import pl.drypisy.R;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Layout used to paint the balloon on the map. Requires layout/balloon.xml.
 * 
 * @author isaac.salgueiro@discalis.com (based on Jeff Gilfelt's
 *         BalloonItemizedOverlay)
 */
public class BalloonLayout extends FrameLayout {
    
    private final LinearLayout layout;
    private final TextView title;
    private final TextView subTitle;
    
    public BalloonLayout(Context context, int balloonBottomOffset) {
        super(context);
        setPadding(10, 0, 10, balloonBottomOffset);
        layout = new LinearLayout(context);
        layout.setVisibility(VISIBLE);
        // FIXME reuse the view
        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View balloonView = inflater.inflate(R.layout.balloon, layout);
        title = (TextView) balloonView.findViewById(R.id.balloon_item_title);
        subTitle = (TextView) balloonView.findViewById(R.id.balloon_item_subtitle);
        
        final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.NO_GRAVITY;
        addView(layout, params);
    }

    /**
     * Sets the text shown into the balloon.
     * 
     * @param text
     */
    public void setText(String titleText, String subTitleTexr) {
        layout.setVisibility(VISIBLE);
        title.setVisibility(VISIBLE);
        title.setText(titleText);
        subTitle.setVisibility(GONE);
        subTitle.setText(subTitleTexr);
    }
    
    
}
